package com.es.web.tomcat;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;


public class TomcatServletFactory extends TomcatServletWebServerFactory{
	@Override
	protected void customizeConnector(Connector connector) {
		connector.setPort(8011);
		super.customizeConnector(connector);
		Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
		connector.setEnableLookups(false);//设置是否反查域名，为了提高处理能力，设置为false
		connector.setURIEncoding("UTF-8");
		protocol.setMaxConnections(10000);//最大连接数 nio默认10000
		//加大并发处理连接数，听加大最大线程数和等待线程数 maxThreads和acceptCount，可以两个设置一样
		protocol.setMaxThreads(2000);//最大线程数，同时处理的任务个数
		protocol.setAcceptCount(2000);//当处理的线程数达到最大时，接收排队的请求个数
		protocol.setMinSpareThreads(100);//最小空闲线程数
		protocol.setCompression("on");//开启gzip压缩，默认关闭
		String compressibleMimeType =  "text/html,text/xml,text/plain,text/css," +
         "text/javascript,application/javascript,application/json,application/xml";
		protocol.setCompressibleMimeType(compressibleMimeType);//压缩类型
		protocol.setCompressionMinSize(2048);//默认2m
		//设置线程池 ，设置了线程池，则前面设置的线程数量失效
		//ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 600, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
		//protocol.setExecutor(threadPoolExecutor);
		protocol.setConnectionTimeout(20000);//连接超时设置20秒
		protocol.setKeepAliveTimeout(60000);//长连接超时时间 1 分钟
		protocol.setDisableUploadTimeout(true);
		
		
	}
	
	
}
